private var buttonWidth : int= 200;
private var buttonHeight : int= 50;
private var width : int = 50;
private var height : int = 30;
private var header : String = "figure     posX     posZ    scale    //pos(-4..4) scale(0..2)";

private var selectedToolbar : int = 0;
private var toolbarStrings : String[] = ["Add cube", "Substract cube", "Add cylinder", "Substract cylinder"];

private var cubeTextFieldStrings = new Array();
private var cylinderTextFieldStrings = new Array();
var allOptions : boolean = false;

function OnGUI ()
{

	selectedToolbar = GUI.Toolbar (Rect (50, 10, Screen.width - 100, 30), selectedToolbar, toolbarStrings);

	allOptions = GUI.Toggle (Rect (50, 45, 150, 20), allOptions, "Toggle Edit/Add");
	GUI.enabled = allOptions;

	GUI.Label (new Rect(50, 65, 400,  20), header);

	var elements : int = 0;
	for  (var  cnt = 0;  cnt <  cubeTextFieldStrings.length;  cnt = cnt + 3)
	{
		var ypos : int = 90 + elements * height + 5;
		GUI.Label (new Rect(50, ypos, 100,  20), "Cube");
		cubeTextFieldStrings[cnt] = GUI.TextField(new Rect(100, ypos, width, height), cubeTextFieldStrings[cnt], 25);
		cubeTextFieldStrings[cnt + 1] = GUI.TextField(new Rect(100 + width, ypos, width, height), cubeTextFieldStrings[cnt + 1], 25);
		cubeTextFieldStrings[cnt + 2] = GUI.TextField(new Rect(100 + 2 * width, ypos, width, height), cubeTextFieldStrings[cnt + 2], 25);
		elements++;
	}

	for  (cnt = 0;  cnt <  cylinderTextFieldStrings.length;  cnt = cnt + 3)
	{
		ypos = 90 + elements * height + 5;
		GUI.Label (new Rect(50, ypos, 100,  20), "Cylinder");
		cylinderTextFieldStrings[cnt] = GUI.TextField(new Rect(100, ypos, width, height), cylinderTextFieldStrings[cnt], 25);
		cylinderTextFieldStrings[cnt + 1] = GUI.TextField(new Rect(100 + width, ypos, width, height), cylinderTextFieldStrings[cnt + 1], 25);
		cylinderTextFieldStrings[cnt + 2] = GUI.TextField(new Rect(100 + 2 * width, ypos, width, height), cylinderTextFieldStrings[cnt + 2], 25);
		elements++;
	}

	/* If the user clicked a new Toolbar button this frame, we'll process their input */
	if (GUI.changed)
	{
		if (!GUI.enabled)
		{
			switch (selectedToolbar)
			{
				case 0: InsertLast3ElementsWithRandVal(cubeTextFieldStrings); break;
				case 1: DeleteLast3Elements(cubeTextFieldStrings); break;
				case 2: InsertLast3ElementsWithRandVal(cylinderTextFieldStrings); break;
				case 3: DeleteLast3Elements(cylinderTextFieldStrings); break;
				default: break;
			}
		}
	}

	/* Start button */
	if (GUI.Button(new Rect(Screen.width / 2 - buttonWidth / 2,
						    Screen.height /2 - buttonHeight / 2,
						    buttonWidth, buttonHeight), "StartLevel"))
	{
		var other :  DataTransfer = GameObject.Find("MenuControl").GetComponent(DataTransfer);
		other.cubePosVectTable = new Array();
		other.cubeSizeVectTable = new Array();
		other.cylinderPosVectTable = new Array();
		other.cylinderSizeVectTable = new Array();

		for (cnt = 0; cnt < cubeTextFieldStrings.length; cnt = cnt + 3)
		{
			var x : float = parseFloat(cubeTextFieldStrings[cnt]);
			var z : float = parseFloat(cubeTextFieldStrings[cnt + 1]);
			other.cubePosVectTable.Push(Vector3(x, 0, z));

			var scale : float= parseFloat(cubeTextFieldStrings[cnt + 2]);
			other.cubeSizeVectTable.Push(Vector3(scale, 1f, scale));
		}

		for (cnt = 0; cnt < cylinderTextFieldStrings.length; cnt = cnt + 3)
		{
			x = parseFloat(cylinderTextFieldStrings[cnt]);
			z = parseFloat(cylinderTextFieldStrings[cnt + 1]);
			other.cylinderPosVectTable.Push(Vector3(x, 0, z));

			scale = parseFloat(cylinderTextFieldStrings[cnt + 2]);
			other.cylinderSizeVectTable.Push(Vector3(scale, 1f, scale));
		}
		Application.LoadLevel(1);
	}
}

function InsertLast3ElementsWithRandVal (array : Array)
{
	for (var cnt : int = 0; cnt < 2; cnt = cnt + 1)
	{
		var floatString : float = Random.Range(-3.5f, 3.5f);
		array.Push(floatString.ToString());
	}

	floatString = Random.Range(1f, 2f);
	array.Push(floatString.ToString());
}

function DeleteLast3Elements (array : Array)
{
	array.Pop();
	array.Pop();
	array.Pop();
}
